#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

class Solution {
public:
  vector<int> getLeastNumbers(vector<int> &arr, int k) {
    if (k == 0) {
      return {};
    }
    if (arr.size() <= k) {
      return arr;
    }
    vector<int> res;
    priority_queue<int, vector<int>, less<int>> restemp;
    for (int i = 0; i < arr.size(); ++i) {
      if (restemp.size() < k) {
        restemp.push(arr[i]);
      } else {
        if (arr[i] < restemp.top()) {
          restemp.pop();
          restemp.push(arr[i]);
        }
      }
    }
    while (!restemp.empty()) {
      res.push_back(restemp.top());
      restemp.pop();
    }
    return res;
  }
};

int main() {
  vector<int> a = {3, 2, 1};
  Solution s;
  auto res = s.getLeastNumbers(a, 2);
}
